package com.fwx.controller;

import com.fwx.entity.Dept;
import com.fwx.service.DeptService;
import com.fwx.vo.R;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @program: springBoot06
 * @description:
 * @author: 范文轩
 * @create: 2024-07-15 10:29
 **/

@RestController
@RequestMapping("/dept")
@Api(value = "部门管理")
public class DeptController {
    
    @Autowired
    private DeptService deptService;

    // 添加部门
    @ApiOperation(value = "添加部门")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "dept",value = "部门实体",required = true,dataType = "Dept")
    )
    @PostMapping("/insert")
    public R insert(@RequestBody Dept dept){
        return deptService.insert(dept);
    }

    // 通过部门编号修改部门信息
    @ApiOperation(value = "通过部门编号修改部门信息")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "dept",value = "部门实体",required = true,dataType = "Dept")
    )
    @PutMapping("/updateById")
    public R updateById(@RequestBody Dept dept){
        return deptService.updateById(dept);
    }

    // 通过部门编号删除
    @ApiOperation(value = "通过部门编号删除")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "deptno",value = "部门编号",required = true,dataType = "int")
    )
    @DeleteMapping("/deleteById")
    public R deleteById(Integer deptno){
        return deptService.deleteById(deptno);
    }

    // 分页查询全部部门信息
    @ApiOperation(value = "分页查询全部部门信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "当前页数", required = true, dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", required = true, dataType = "int")
    })
    @GetMapping("/selectAll")
    public R selectAll(Integer current,Integer size){
        return deptService.selectAll(current,size);
    }

    // 根据部门编号查询
    @ApiOperation(value = "根据部门编号查询")
    @ApiImplicitParams(
            @ApiImplicitParam(name = "deptno",value = "部门编号",required = true,dataType = "int")
    )
    @GetMapping("/selectByEmpNo")
    public R selectById(Integer deptno){
        return deptService.selectByDeptNo(deptno);
    }
}
